@extends('admin.layouts.master')
@section('css')
<link rel="stylesheet" href="{{asset('assets/icheck/skins/all.css')}}">
<style>
    /*master引入后显示==会员管理*/
    .system_manage{
        background: #393F64;
    }
    /*搜索框所在的区域*/
    .main_header{
        float: left;
        margin-top: 8px;
        width:100%;
        height: 100px;
        line-height: 100px;

    }
    .main_header_search{
        float: left;
        width: 155px;
        position: relative;
    }
    .main_header_search input{
        border-radius:6px;
        width: 215px;
        height: 40px;
        margin-top: 30px;
        border: 0px solid;
    }
    /*.main_header_search input:hover{*/
    /*box-shadow: 0 8px 12px rgba(0,0,0,0.2);*/
    /*}*/

    /*.main_header_search input{*/
    /*padding-left:45px;*/
    /*font-size: 16px;*/
    /*color:#ccc;*/
    /*}*/
    /*================*/
    .main_header_add{
        float: right;
        width: 215px;
        height: 100px;
        line-height: 100px;
        text-align: right;

    }
    .add_box {
        float: right;
        width: 90px;
        height: 40px;
        margin-top: 32px;
        background: #fff;
        line-height: 40px;
        cursor: pointer;
        border-radius: 6px;
        margin-left:17px;
    }
    .add_box:hover{
        box-shadow: 0 8px 12px rgba(0,0,0,0.2);
    }

    .add_box img{
        float:left;
        margin-top:6px;
        margin-left:6px;
        width: 28px;
        height: 28px;
        line-height: 40px;
    }
    .add_box span{
        float: left;
        font-size:18px;
        margin-left: 8px;
        color:  #24a7f6;
    }
    /*======主要内容区=====*/
    .main_form{
        float: left;
        width: 100%;
        height: 783px;
        background: #fff;
        border-radius: 10px;
        box-shadow: 0 8px 12px rgba(0,0,0,0.2);
    }
    .main_formlist{
        margin-top:30px;
    }
    .main_table{
        width: 94%;
        margin: 0 auto;
        border: 1px solid #B1B1B1;
    }
    .main_table tr{
        height: 15px;
        width: 100%;
    }
    .main_table tr th{
        text-align: center;
        line-height: 20px;
        height: 20px;
        font-size: 18px;
    }
    .main_table tr td{
        text-align: center;
    }
    /*======操作中的编辑与删除的样式======*/
    .formlist_handle a{
        font-size:18px;
        text-decoration: none;
    }
    .formlist_handle span{
        font-size:18px;
        cursor: pointer;
    }
    .formlist_edit{
        color: #79C9F7;
    }
    .formlist_destory{
        color: red;
    }

    /*laravel自带的分页样式*/
    .boot_fenye{
        margin: 0 auto;
        margin-top:2px;
        width: 94%;
        height: 55px;
    }
    .boot_page{
        float: right;

    }
    .boot_page_di{
        margin-left: 10px;
        float: left;
        text-align: right;
        font-size: 14px;
        height: 74px;
        line-height: 74px;

    }
    .boot_page_di_span{
        width: 34px;
        height: 34px;
        border: 1px solid #D6D6D1;
    }
    .boot_page_total{
        margin-left: 10px;
        float:left;
        text-align: right;
        font-size: 14px;
        height: 74px;
        line-height: 74px;


    }
    .boot_choose{
        margin-left:20px;
        float:right;
    }

</style>
@endsection
@section('content')
<form id="editForm">
    <div class="main_header clearfix">
        <span><a style="color:white;font-size: 18px" href="/admin/role">角色管理</a><span style="color:white;font-size: 18px">&nbsp;&nbsp;>&nbsp;&nbsp;角色编辑</span></span>

        <div class="main_header_add clearfix">
            <button type="submit" class="btn btn-info">保存</button>
        </div>
    </div>
    <div  class="main_form clearfix">
        <div class="main_formlist"  style="padding: 40px">
            <div class="form-group">
                <label>角色名</label>
                <input name="name" type="text" value="{{$role->name}}" class="form-control" required>
                <div class="help-block with-errors"></div>
            </div>
            <div class="form-group">
                <label>角色标识</label>
                <input name="slug" type="text" value="{{$role->slug}}" class="form-control" required>
                <div class="help-block with-errors"></div>
            </div>
            <div class="form-group">
                <label>角色权限</label>
                <div>
                    @foreach($allPermissions as $permission)
                    <div style="float: left;"><input name="permissions[]" type="checkbox" value="{{$permission->id}}" @if(in_array($permission->id,$role->permissions->pluck('id')->toArray())) checked @endif>{{$permission->name}}&nbsp;&nbsp;</div>
                    @endforeach
                    <div style="clear: both"></div>
                </div>
                <div class="help-block with-errors"></div>
            </div>
        </div>
    </div>
</form>

@endsection
@section('js')
    <script src="{{asset('assets/icheck/icheck.min.js')}}"></script>
    <script>
    $('input').iCheck({
        checkboxClass: 'icheckbox_flat-blue',
        radioClass: 'iradio_flat-blue'
    });
    $('#editForm').validator().on('submit', function (e) {
        if (!e.isDefaultPrevented()) {
            layer.load(1, {shade: [0.1, '#fff']});
            $.ajax({
                     url: "/admin/role/" + {{$role->id}},
                    type: 'put',
                    dataType: "json",
                    data: $("#editForm").serialize(),
                    success: function (res) {
                        layer.closeAll();
                            if (res.status == 1) {
                            layer.msg(res.msg, {icon: 1});
                            location.href = "/admin/role";
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }
                    }
            });
        }
        return false;
    })
</script>
@endsection


